//
//  DDReplyMeVC.m
//  dingdang
//
//  Created by 阮 沧晖 on 15/8/4.
//  Copyright (c) 2015年 阮 沧晖. All rights reserved.
//

#import "DDSystemVC.h"
#import "DDPushDB.h"
@interface DDSystemVC ()

@property(nonatomic,strong)NSArray *datas;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation DDSystemVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createUI];
    [self createData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)createUI
{
    
    __weak DDSystemVC *weakSelf = self;
    self.view.backgroundColor = RGB(245, 245, 245);
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    //自定义TAB BAR UI
    [self addNavigatorTitle:NSLocalizedString(@"系统消息", nil) parent:self.view];
    self.barViewControl.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_Background"]];
    [self AddLeftBtnAction:nil normal:@"top_返回" selected:@"top_返回" action:^{
        //[self dismissViewControllerAnimated:YES completion:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }];
    [self AddRightBtnAction:@"全部清除" normal:nil selected:nil action:^{
        if([DDPushDB deleteWithWhere:@"type=4"]){
            [weakSelf delayHUD:@"清除成功"];
        }
    }];

}

- (void)createData
{
    NSMutableArray *pushDB = [DDPushDB searchWithWhere:@"type=4" orderBy:nil offset:0 count:0];
    _datas = pushDB;
    
    if (_datas.count == 0) {
        self.tableView.hidden = YES;
        UIImageView *noneImageView = [[UIImageView alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width/2-61 ,[[UIScreen mainScreen] bounds].size.height/2-71, 122, 142)];
        noneImageView.image = [UIImage imageNamed:@"无内容页"];
        [self.view addSubview:noneImageView];
    }else{
        
    }
    
}

#pragma mark -UITableDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _datas.count;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"UITableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    DDPushDB *push = _datas[indexPath.section];
    
    if ([push.unRead isEqualToString:@"0"]) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 14, 12, 12)];
        imageView.image = [UIImage imageNamed:@"提醒-圆点-底"];
        [cell.contentView addSubview:imageView];
    }
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 7, self.tableView.frame.size.width, 30)];
    label.text =@"12312312";
    label.textColor = [UIColor lightGrayColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont fontWithName:@"Arial" size:18.0];
    [cell.contentView addSubview:label];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    DDPushDB *push = _datas[indexPath.section];
    push.unRead = @"1";
    [push save];
    [self.tableView reloadData];
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"123123" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    
//    AnswerWoFixViewController * answerWo = [[AnswerWoFixViewController alloc]init];
//    answerWo.pushDB = push;
//    [self.navigationController pushViewController:answerWo animated:YES];
}
@end
